package com.gutils.cursor
{
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.Event;

	public class CursorMaker
	{
		private static var instance:CursorMaker = new CursorMaker();

		public function CursorMaker(lock:Lock)
		{
			if ( lock == null )
				throw new Error( "Singleton and can only be accessed through CursorMaker.getInstance()" ); 
		}
		
		public static function getInstance():CursorMaker 
		{	
			if ( instance == null ) 
				instance = new CursorMaker( new Lock() );
			return instance;		
		}
		
		private var clip:MovieClip;
		private var stage:Stage;
		public function create($stage:Stage, $clip:MovieClip):void
		{
			clip  = $clip;
			stage = $stage;
			
			if (clip != null)
			{
				stage.removeChild(clip);
				stage.removeEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
			}
			clip = new MovieClip();
			stage.addChild(clip);
			stage.addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
			
		}
		
		private function onEnterFrameHandler(event:Event):void
		{
			clip.mouseEnabled = false;
			clip.x = stage.mouseX;
			clip.y = stage.mouseY;
			
		}
	}
}
internal class Lock{}